# test01_time.py
# 打开文件，读取每一行日志
# while + readline
# for + readlines
from time import strptime
# 将2024-12-28 22:00:00转为结构化时间
t1 = strptime('2024-12-28 22:00:00', '%Y-%m-%d %H:%M:%S')
# 将2024-12-29 02:00:00转为结构化时间
t2 = strptime('2024-12-29 02:00:00', '%Y-%m-%d %H:%M:%S')
with open('apache.txt', mode='r') as fr:
    for line in fr.readlines():
        # print(line, end='')
        # 获取日期时间部分
        # print(line[:19])
        # 转为结构化时间
        t = strptime(line[:19], '%Y-%m-%d %H:%M:%S')
        # print(t)
        # 判断是否在指定的区间
        if t1 <= t <= t2:
            print(line, end='')